<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改信息</title>
</head>
<body>
<h1>修改员工页面</h1>
<form action="">
    <input type="text" name="id" v-model="emp.id" readonly placeholder="id">
    <input type="text" name="name" v-model="emp.name" placeholder="名字">
    <input type="text" name="job" v-model="emp.job" placeholder="工作">
    <input type="text" name="age" v-model="emp.age" placeholder="年龄">
    <input type="text" name="salary" v-model="emp.salary" placeholder="工资">
    <input type="button" value="修改" @click="update()">
</form>

<!--引入axios和vue-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

<script>
    //得到列表页面传递过来的员工ID
    let id = location.search.split("=")[1]
    console.log("员工id="+id)
    let v = new Vue({
        el:"form",
        data:{
            emp:{}
        },
        created:function () {
            axios.get("/selectById?id="+id).then(function (response) {
                v.emp = response.data;
            })
        },
        methods:{
            update:function () {
                if (confirm("确定修改吗?")){
                    //得到form表单中的数据
                    let data = new FormData(document.querySelector("form"));
                    axios.post("/update",data).then(function () {
                        //修改完成回到列表页面
                        location.href = "/list.html";
                    })
                }
            }
        }
    })
</script>
</body>
</html>